//
//  SRAlbumListCollectionViewCell.m
//  StoryShow
//
//  Created by CyonLeuMBP on 2017/3/31.
//  Copyright © 2017年 qudiandu.cn. All rights reserved.
//

#import "SRAlbumListCollectionViewCell.h"

NSString *const kSRAlbumListCollectionViewCell = @"SRAlbumListCollectionViewCell";

@implementation SRAlbumListCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    FZStyleSheet *css = [FZStyleSheet currentStyleSheet];
    
    self.coverImageView.layer.cornerRadius = css.buttonCornerRadius;
    self.coverImageView.layer.masksToBounds = YES;
    self.contentView.backgroundColor = css.color_2;
    
    self.titleLabel.textColor = css.color_4;
    self.titleLabel.font = css.fontOfH3;
    
    [self.checkButton setImage:[UIImage imageNamed:@"common_btn_checkbox"] forState:UIControlStateNormal];
    [self.checkButton setImage:[UIImage imageNamed:@"common_btn_checkbox_sel"] forState:UIControlStateSelected];
    
    self.checkButtonHidden = YES;
}

- (void)setCheckButtonHidden:(BOOL)checkButtonHidden {
    _checkButtonHidden = checkButtonHidden;
    
    self.checkButton.hidden = checkButtonHidden;
}

- (void)setSelected:(BOOL)selected {
    [super setSelected:selected];
    
    self.checkButtonStatus = selected;
    self.albumModel.isSelected = selected;
}

- (void)setCheckButtonStatus:(BOOL)isChecked {
    [self.checkButton setSelected:isChecked];
}

- (IBAction)onClickButtonAction:(UIButton *)sender {
    
    if (sender.isSelected) {
        sender.selected = !sender.selected;
        if (self.delegate && [self.delegate respondsToSelector:@selector(albumListCollectionViewCell:deselectItemIndexPath:)]) {
            [self.delegate albumListCollectionViewCell:self deselectItemIndexPath:self.indexPath];
        }
    } else {
        
        sender.selected = !sender.selected;
        if (self.delegate && [self.delegate respondsToSelector:@selector(albumListCollectionViewCell:didSelectItemIndexPath:)]) {
            [self.delegate albumListCollectionViewCell:self didSelectItemIndexPath:self.indexPath];
        }
    }
}

- (void)updateCellInfo:(id)data {
    
    if (!data && ![data isKindOfClass:[FZHomeCourseModel class]]) {
        return;
    }
    self.albumModel = data;
    FZHomeCourseModel *item = (FZHomeCourseModel *)data;
    self.titleLabel.text = item.title;
    self.checkButtonStatus = item.isSelected;
    [self.coverImageView fz_setImageWithDefaultPlaceholderWithURL:[NSURL URLWithString:item.pic] placeholderSize:self.coverImageView.bounds.size];
}



@end
